#include "sdl_helper.h"

/* loads a bitmap image using SDL
 * returns the requested texture
 * returns 0 on error
 */
SDL_Texture *dd_load_bmp(const char *filepath) {

	// load the surface
	SDL_Surface *bmp = SDL_LoadBMP(filepath);
	if (!bmp){
		printf("SDL_LoadBMP Error: %s\n", SDL_GetError());
		return 0;
	}

	// load the texture
	SDL_Texture *tex = SDL_CreateTextureFromSurface(dd_ren, bmp);
	SDL_FreeSurface(bmp);
	if (!tex){
		SDL_FreeSurface(bmp);
		printf("SDL_CreateTextureFromSurface Error: %s\n", SDL_GetError());
		return 0;
	}

	return tex;
}

/* loads any type of image using the SDL_Image extension
 * returns the requested texture
 * returns 0 on error
 */
SDL_Texture *dd_load_image(const char *file){
	SDL_Texture *texture = IMG_LoadTexture(dd_ren, file);
	if (!texture){
		printf("IMG_LoadTexture Error: %s\n", SDL_GetError());
		return 0;
	}
	return texture;
}
